package com.culturalCenter.dataCenter.service.impl.volunteer;


import com.culturalCenter.dataCenter.customEntity.responseParam.volunteer.VolunteerResponse;
import com.culturalCenter.dataCenter.entity.volunteer.CdcVolunteer;
import com.culturalCenter.dataCenter.mapper.volunteer.CdcVolunteerMapper;
import com.culturalCenter.dataCenter.service.volunteer.CdcVolunteerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 志愿者信息(CdcVolunteer)表服务实现类
 *
 * @author makejava
 * @since 2021-09-17 16:09:53
 */
@Service("cdcVolunteerService")
public class CdcVolunteerServiceImpl implements CdcVolunteerService {

    @Resource
    private CdcVolunteerMapper cdcVolunteerMapper;

    @Override
    public CdcVolunteer queryById(String id) {
        return this.cdcVolunteerMapper.queryById(id);
    }

    @Override
    public List<CdcVolunteer> queryAllByLimit(int offset, int limit) {
        return this.cdcVolunteerMapper.queryAllByLimit(offset, limit);
    }

    @Override
    public CdcVolunteer insert(CdcVolunteer cdcVolunteer) {
        this.cdcVolunteerMapper.insert(cdcVolunteer);
        return cdcVolunteer;
    }

    @Override
    public CdcVolunteer update(CdcVolunteer cdcVolunteer) {
        this.cdcVolunteerMapper.update(cdcVolunteer);
        return this.queryById(cdcVolunteer.getId());
    }

    @Override
    public boolean deleteById(String id) {
        return this.cdcVolunteerMapper.deleteById(id) > 0;
    }

    @Override
    public VolunteerResponse userStatistics() {
        VolunteerResponse volunteer = new VolunteerResponse();
        volunteer.setTotal(cdcVolunteerMapper.getTotal());

        Map<String, Integer> genderStatistics = new LinkedHashMap<>();
        genderStatistics.put("男", cdcVolunteerMapper.getGenderNumber(1));
        genderStatistics.put("女", cdcVolunteerMapper.getGenderNumber(0));
        volunteer.setGenderStatistics(genderStatistics);

        Map<String, Integer> ageStatistics = new LinkedHashMap<>();
        String age;
        for (int i = 10; i < 100; i += 10) {
            age = i + "-" + (i + 9);
            ageStatistics.put(age, cdcVolunteerMapper.getAgeNumber(i, i + 9));
        }
        volunteer.setAgeStatistics(ageStatistics);
        return volunteer;
    }

}
